//
//  PhoneLogin.m
//  YIChuSeller
//
//  Created by admin on 2018/11/28.
//  Copyright © 2018 xiangshengjun. All rights reserved.
//

#import "PhoneLogin.h"
#import "GXRegisterViewController.h"
#import "GXMainTabBarController.h"
@interface PhoneLogin ()
@property (weak, nonatomic) IBOutlet UITextField *phoneTF;
@property (weak, nonatomic) IBOutlet UITextField *codeTF;

@end
@implementation PhoneLogin
- (void)awakeFromNib{
    [super awakeFromNib];
}
+(instancetype)phoneLogin
{
    return [[NSBundle mainBundle]loadNibNamed:@"PhoneLogin" owner:nil options:nil].lastObject;
}
- (IBAction)pressRegistBtn:(UIButton *)sender {
    GXRegisterViewController * registVC = [[GXRegisterViewController alloc]init];
    [self.getViewController presentViewController:registVC animated:YES completion:nil];
}
- (IBAction)pressCodeBtn:(id)sender {
    if (![self checkPhoneNumberValue]) {
        return;
    }
    [SVProgressHUD showErrorWithStatus:@"请输入6位验证码"];
}
- (IBAction)pressLoginBtn:(UIButton *)sender {
    if (![self checkCodeNumberValue]) {
        return ;
    }
    [SVProgressHUD showErrorWithStatus:@"暂未开通"];
//    [MBProgressHUD showMessage:@"登录中..."];
//    NSDictionary * jsonStr = [NSDictionary dictionary];
//    jsonStr = @{@"api":@"YCS_USER_ISEXIST",
//                @"parameters":@{
//                        @"phone":self.phoneTF.text,
//                        @"email":@"",
//                        @"password":
//                        }
//                };
//    [HttpHelper Post:kBaseURL parameters:jsonStr success:^(id responseObject) {
//        [MBProgressHUD hideHUD];
//        if ([responseObject[@"cod"] isEqualToString:@"001"]) {
//            [MBProgressHUD showSuccess:@"注册成功,登录中" toView:self];
//            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//                GXMainTabBarController * mainVC = [[GXMainTabBarController alloc]init];
//                UIWindow * mainWindow = [UIApplication sharedApplication].keyWindow;
//                mainVC.selectedIndex = 1;
//                mainWindow.rootViewController = mainVC;
//            });
//        }else{
//            [MBProgressHUD showError:responseObject[@"describa"]];
//        }
//    } failure:^(NSError *error) {
//        [MBProgressHUD hideHUD];
//    }];
}

- (BOOL)checkCodeNumberValue
{
    if ([NSString isBlankString:self.codeTF.text]) {
        [SVProgressHUD showErrorWithStatus:@"验证码不能为空"];
        return NO;
    }
    if (self.codeTF.text.length != 6) {
        [SVProgressHUD showErrorWithStatus:@"请注意验证码的长度为6"];
        return NO;
    }
    return YES;
}
- (BOOL)checkPhoneNumberValue
{
    if ([NSString isBlankString:self.phoneTF.text]) {
        [SVProgressHUD showErrorWithStatus:@"手机号不能为空"];
        return NO;
    }
    if (self.phoneTF.text.length !=11) {
        [SVProgressHUD showErrorWithStatus:@"输入手机号不正确"];
        return NO;
    }
    return YES;
}
@end
